home *** CD-ROM | disk | FTP | other *** search
/ WINMX Assorted Textfiles / Ebooks.tar / Text - Tech - OS - Unix - Tips.txt < prev    next >
Text File  |  2003-09-27  |  24KB  |  655 lines

  1.                        *** A List Of Some OF The Most Useful UNIX **
  2.      *** Hacking Commands, and Some Hints On Their Usage ***
  3.        
  4. ---------------------------------------------------------------
  5.  
  6.      It is fun and often usefull to create a file that is owned 
  7. by someone else.  On most systems with slack security ie 99% of 
  8. all UNIX systems, this is quite easily done.  The chown command 
  9. will change any of your files to make someone else the owner. 
  10. Format is as follows:
  11.  
  12. chown ownername filelist
  13.  
  14.  Where ownername is the new owner, and filelist is the list of 
  15. files to change.  You must own the file which your are goin to 
  16. change, unless you are a superuser....then u can change ANYTHING!
  17.      chgrp is a similar command which will change the group 
  18. ownership on a file.  If you are going to do both a chown and a 
  19. chgrp on a file, then make sure you do the chgrp first!  Once the 
  20. file is owned by someone else, you cant change nything about it!
  21.  
  22. ---------------------------------------------------------------
  23.  
  24.      Sometimes just seeing who is on the system is a challenge in 
  25. itself.  The best way is to write your own version of who in C, 
  26. but if you can't do that then this may be of some help to you:
  27.  
  28.      who   followed by on or more of the following flags:
  29.  
  30.           -b Displays time sys as last booted.
  31.           -H Precedes output with header.
  32.           -l Lists lines waiting for users to logon.
  33.           -q displays number of users logged on.
  34.           -t displays time sys clock was last changed.
  35.           -T displays the state field (a + indicates it is 
  36. possible to send to terminal, a - means u cannot)
  37.           -u Give a complete listing of those logged on.
  38.  
  39.    **who -HTu is about the best choice for the average user**
  40.  
  41. ##by the way, the list of users logged on is kept in the file 
  42. /etc/utmp.  If you want to write your own personalised version of 
  43. who in C, you now know where to look!###
  44.  
  45. --------------------------------------------------------------- 
  46.  
  47.      When a users state field (see -T flag option for who 
  48. command) says that a user has their message function on, this 
  49. actually means that it is possible to get stuff onto their 
  50. screen.
  51.      Basically, every terminal on the system has a file 
  52. corresponding to it.  These files can be found in the /dev 
  53. directory.  You can to anything to these files, so long as you 
  54. have access -eg you can read them, and write to them, but you 
  55. will notice that they never change in size.  They are called 
  56. character specific files, and are really the link between the 
  57. system and the terminals.  Whatever you put in these files will 
  58. go staright to the terminal it corresponds to.
  59.      Unfortunately, on most systems, when the user logs in, the 
  60. "mesg n" command is issued which turns off write access to that 
  61. terminal, BUT- if you can start cating to that terminal before 
  62. system issues the mesg n command, then you will continue to be 
  63. able to get stuff up on that terminal! This has many varied uses.
  64.  
  65.      Check out the terminal, or terminal software being used.  
  66. Often you will be able to remotely program another users 
  67. terminal, simply by 'cating' a string to a users screen.  You 
  68. might be able to set up a buffer, capturing all that is typed, or 
  69. you may be able to send the terminal into a frenzy- (sometimes a 
  70. user will walk away without realizing that they are sill 
  71. effectively logged on, leaving you with access to their 
  72. account!).  Some terminal types also have this great command 
  73. called transmit screen. It transmits everything on the screen, 
  74. just as if the user had typed it !
  75.      So just say I wanted to log off a user, then I would send a 
  76. clear screen command (usually ctrl l), followed by "exit" 
  77. followed by a carriage return, followed by the transmit screen 
  78. code.  Using ths technique you can wipe peoples directories or 
  79. anything.  My favourite is to set open access on all their files 
  80. and directories so I can peruse them for deletion etc at my own 
  81. leisure).            
  82.  
  83. ---------------------------------------------------------------
  84.  
  85.      If you ever briefly get access to another persons account 
  86. eg. they leave the room to go to toilet or whatever, then simply 
  87. type the following:
  88.  
  89. chmod 777 $HOME
  90. chmod 777 $MAIL
  91.  
  92.      Then clear the screen so they dont see what you just typed.
  93.  
  94.      Now you can go look at their directory, and their mail, and 
  95. you can even put mail in their mail file. (just use the same 
  96. format as any mail that is already there!). Next time they log in 
  97. the system will automatically inform them they have new mail!
  98.  
  99. ---------------------------------------------------------------
  100.  
  101.      Another way to send fake mail to people is to use the mail 
  102. server.  This method produces mail that is slightly different to 
  103. normal, so anyone who uses UNIX a bit may be suspiscious when 
  104. they receive it, but it will fool the average  user!
  105.  
  106. type telnet
  107.  
  108. the following prompt will appear:
  109.  
  110. telnet>
  111.  
  112. now type :
  113.  
  114. open localhost 25
  115.  
  116. some crap will come up about the mail server..now type:
  117.  
  118. mail from: xxxxxx     Put any name you want.
  119.  
  120. some more bullshit will come up. Now type:
  121.  
  122. rcpt to: xxxxxx  Put the name of the person to receive mail here.
  123.  
  124. now type:
  125.  
  126. data
  127.  
  128. now you can type the letter...end it with a "."
  129. type quit to exit once you are done.
  130.  
  131. -------------------------------------------------------------
  132.  
  133.      Heres one for any experimenters out there...
  134. It is possible to create files which simply cannot be deleted 
  135. from the standard shell.  To do this you will have to physically 
  136. CREATE THE FILE USING A C PROGRAM or SCRIPT FILE, and you will 
  137. have to use a sequence of control characters which cannot be 
  138. typed from the shell.  Try things like Ctrl-h (this is the 
  139. code for the delete key).  Just a file with the name Ctrl-h would 
  140. not be deleteable from the shell, unless you used wildcards. So, 
  141. make it a nice long series of characters, so that to delete the 
  142. file, the user has no choice but to individually copy all his 
  143. files elsewhere, then delete everything in his directory, and 
  144. then copy all his files back.....this is one of my 
  145. favourites..gets em every time!
  146.      
  147.      The following script file is an example which will create a 
  148. file with the name Ctrl-h.  You MUST tyoe this file in using the 
  149. vi editor or similar.
  150. *****If you are not very good with vi, type "man vi" and print the 
  151. help file...it even contains stuff that I find useful now and 
  152. then.*****
  153.  
  154. type the following in vi...
  155.  
  156. echo'' > 'a^h'
  157.  
  158.   ***NOTE...to get the ^h (this really means ctrl-h) from vi type:
  159.  
  160. Ctrl v
  161. Ctrl h 
  162.  
  163.   The Ctrl v instrcts vi to take the next character as a ascii 
  164. character, and not to interpret it.
  165.      change the access on the file you just created and now 
  166. execute it.  It will create a file which looks like it is called 
  167. a, but try to delete it !..use wildcards if you really want to 
  168. delete it. 
  169.  
  170. *> Title:   Tutorial on hacking through a UNIX system
  171.  
  172.  
  173. ** 
  174.  
  175. In the following file, all references made to the name Unix, may also be 
  176. substituted to the Xenix operating system. 
  177.  
  178. Brief history:  Back in the early sixties, during the development of 
  179. third generation computers at MIT, a group of programmers studying the 
  180. potential of computers, discovered their ability of performing two or 
  181. more tasks simultaneously.  Bell Labs, taking notice of this discovery, 
  182. provided funds for their developmental scientists to investigate into this 
  183. new frontier.  After about 2 years of developmental research, they produced 
  184. an operating system they called "Unix".  
  185. Sixties to Current:  During this time Bell Systems installed the Unix system 
  186. to provide their computer operators with the ability to multitask so that 
  187. they could become more productive, and efficient.  One of the systems they
  188. put on the Unix system was called "Elmos". Through Elmos many tasks (i.e.
  189. billing,and installation records) could be done by many people using the same 
  190. mainframe. 
  191.  
  192. Note: Cosmos is accessed through the Elmos system. 
  193.  
  194. Current:  Today, with the development of micro computers, such multitasking 
  195. can be achieved by a scaled down version of Unix (but just as 
  196. powerful).  Microsoft,seeing this development, opted to develop their own 
  197. Unix like system for the IBM line of PC/XT's.  Their result they called 
  198. Xenix (pronounced zee-nicks).  Both Unix and Xenix can be easily installed 
  199. on IBM PC's and offer the same function (just 2 different vendors). 
  200.  
  201. Note: Due to the many different versions of Unix (Berkley Unix, 
  202. Bell System III, and System V the most popular) many commands 
  203. following may/may not work. I have written them in System V routines. 
  204. Unix/Xenix operating systems will be considered identical systems below. 
  205.  
  206. How to tell if/if not you are on a Unix system:  Unix systems are quite 
  207. common systems across the country. Their security appears as such: 
  208.  
  209. Login;     (or login;) 
  210. password: 
  211.  
  212. When hacking on a Unix system it is best to use lowercase because the Unix 
  213. system commands are all done in lower- case. Login; is a 1-8 character field. It is 
  214. usually the name (i.e. joe or fred) of the user, or initials (i.e. j.jones 
  215. or f.wilson).  Hints for login names can be found trashing the location of 
  216. the dial-up (use your CN/A to find where the computer is). Password: is a 1-8 character password assigned by the sysop or chosen by the user. 
  217.    
  218.    Common default logins 
  219.    -------------------------- 
  220.    login;       Password: 
  221.    root         root,system,etc.. 
  222.    sys          sys,system 
  223.    daemon       daemon 
  224.    uucp         uucp 
  225.    tty          tty 
  226.    test         test 
  227.    unix         unix 
  228.    bin          bin 
  229.    adm          adm 
  230.    who          who 
  231.    learn        learn 
  232.    uuhost       uuhost 
  233.    nuucp        nuucp 
  234.  
  235. If you guess a login name and you are not asked for a password, and have 
  236. accessed to the system, then you have what is known as a non-gifted account. 
  237. If you guess a correct login and pass- word, then you have a user account. 
  238. And, if you get the root p/w you have a "super-user" account. 
  239. All Unix systems have the following installed to their system: 
  240. root, sys, bin, daemon, uucp, adm Once you are in the system, you will 
  241. get a prompt. Common prompts are: 
  242.  
  243.  
  244. But can be just about anything the sysop or user wants it to be. 
  245.  
  246. Things to do when you are in: Some of the commands that you may want to 
  247. try follow below: 
  248.  
  249. who is on  (shows who is currently logged on the system.) 
  250. write name (name is the person you wish to chat with) 
  251. To exit chat mode try ctrl-D. 
  252. EOT=End of Transfer. 
  253. ls -a      (list all files in current   directory.) 
  254. du -a      (checks amount of memory  your files use;disk usage) 
  255. cd\name    (name is the name of the sub-directory you choose) 
  256. cd\        (brings your home directory  to current use) 
  257. cat name   (name is a filename either  a program or documentation  your username has written) 
  258.  Most Unix programs are written  in the C language or Pascal 
  259.  since Unix is a programmers'  environment. One of the first things done on the 
  260. system is print up or capture (in a buffer) the file containing all user names and accounts. This can be done by doing the following command: 
  261.  
  262. cat /etc/passwd 
  263.  
  264. If you are successful you will see a list of all accounts on the system.  It 
  265. should look like this:  
  266. root:hvnsdcf:0:0:root dir:/: joe:majdnfd:1:1:Joe Cool:/bin:/bin/joe hal::1:2:Hal Smith:/bin:/bin/hal 
  267.  
  268. The "root" line tells the following info : 
  269. login name=root 
  270. hvnsdcf   = encrypted password 
  271. 0         = user group number 
  272. 0         = user number 
  273. root dir  = name of user 
  274. /         = root directory 
  275.  
  276. In the Joe login, the last part "/bin/joe " tells us which directory 
  277. is his home directory (joe) is. In the "hal" example the login name is 
  278. followed by 2 colons, that means that there is no password needed to get in 
  279. using his name. 
  280.  
  281. Conclusion:  I hope that this file will help other novice Unix hackers 
  282. obtain access to the Unix/Xenix systems that they may find.
  283.  
  284.  
  285.  
  286.               On the Security of UNIX
  287.  
  288.               =-=-=-=-=-=-=-=-=-=-=-=
  289.  
  290. Recently there has been much interest in the security aspects of operating
  291.  
  292. systems and software.At issue is the ability to prevent undesired disclosure of
  293.  
  294. information, destruction of information,and harm to the functioning of the
  295.  
  296. system.This paper discusses the degree of security which can be provided under
  297.  
  298. the system and offers a number of hints on how to improve security.The first
  299.  
  300. fact to face is that UNIX was not developed with security,in any realistic
  301.  
  302. sense,in mind;this fact alone guarantees a vast number of holes.(Actually the
  303.  
  304. same statement can be made with respect to most systems.)
  305.  
  306.  
  307.  
  308. The area of security in which is theoretically weakest is in protecting against
  309.  
  310. crashing or at least crippling the operation of the system.The problem here is
  311.  
  312. not mainly in uncritical acceptance of bad parameters to system calls (there
  313.  
  314. may be bugs in this area, but none are known)but rather in lack of checks for
  315.  
  316. excessive consumption of resources.
  317.  
  318.  
  319.  
  320. Most notably, there is no limit on the amount of disk storage used, either in
  321.  
  322. total space allocated or in the number of files or directories.Here is a
  323.  
  324. particularly ghastly shell sequence guaranteed to stop the system:
  325.  
  326.  
  327.  
  328.  
  329.  
  330. while : ; do
  331.  
  332.     mkdir x
  333.  
  334.     cd x
  335.  
  336. done
  337.  
  338.  
  339.  
  340. Either a panic will occur because all the i-nodes on the device are used up,
  341.  
  342. or all the disk blocks will be consumed, thus preventing anyone from writing
  343.  
  344. files on the device.In this version of the system,users are prevented from
  345.  
  346. creating more than a set number of processes simultaneously,so unless users
  347.  
  348. are in collusion it is unlikely that any one can stop the system altogether.
  349.  
  350.  
  351.  
  352. However, creation of 20 or so CPU or disk-bound jobs leaves few resources
  353.  
  354. available for others.Also, if many large jobs are run simultaneously,swap space
  355.  
  356. may run out, causing a panic.  It should be evident that excessive consumption
  357.  
  358. of diskspace, files, swap space and processes can easily occur accidentally in
  359.  
  360. malfunctioning programs as well as at command level.In fact UNIX is essentially
  361.  
  362. defenseless against this kind of abuse,nor is there any easy fix.The best that
  363.  
  364. can be said is that it is generally fairly easy to detect what has happened
  365.  
  366. when disaster strikes ,to identify the user responsible, and take appropriate
  367.  
  368. action.In practice,we have found that difficulties in this area are rather
  369.  
  370. rare,but we have not been faced with malicious users,and enjoy a fairly
  371.  
  372. generous supply of resources which have served to cushion us against accidental
  373.  
  374. overconsumption.
  375.  
  376.  
  377.  
  378. The picture is considerably brighter in the area of protection of information
  379.  
  380. from unauthorized perusal and destruction.Here the degree of security seems
  381.  
  382. (almost) adequate theoretically, and the problems lie more in the necessity for
  383.  
  384. care in the actual use of the system.Each UNIX file has associated with it
  385.  
  386. eleven bits of protection information together with a user identification
  387.  
  388. number and a user-group identification number (UID and GID).
  389.  
  390.  
  391.  
  392. Nine of the protection bits are used to specify independently permission to
  393.  
  394. read, to write, and to execute the file to the user himself, to members of the
  395.  
  396. user's group, and to all other users.Each process generated by or for a user
  397.  
  398. has associated with it an effective UID and a real UID, and an effective and
  399.  
  400. real GID.When an attempt is made to access the file for reading, writing, or
  401.  
  402. executing UID for the process is changed to the UID associated with the file;
  403.  
  404. the change persists until the process terminates or until the UID changed again
  405.  
  406. by another execution of a set-UID file.Similarly the effective group ID of a
  407.  
  408. process is changed to the GID associated with a file when that file is executed
  409.  
  410. and has the set-GID bit set.The real UID and GID of a process do not change
  411.  
  412. when any file is executed,but only as the result of a privileged system
  413.  
  414. call.The basic notion of the set-UID and set-GID bits is that one may write a
  415.  
  416. program which is executableby others and which maintains files accessible to
  417.  
  418. others only by that program.
  419.  
  420.  
  421.  
  422. The classical example is the game-playing program which maintains records of
  423.  
  424. the scores of its players.The program itself has to read and write the score
  425.  
  426. file,but no one but the game's sponsor can be allowed unrestricted access to
  427.  
  428. the file lest they manipulate the game to their own advantage.
  429.  
  430.  
  431.  
  432. The solution is to turn on the set-UID bit of the game program.  When, and only
  433.  
  434. when,it is invoked by players of the game,it may update the score file but
  435.  
  436. ordinary programs executed by others cannot access the score.  There are a
  437.  
  438. number of special cases involved in determining access permissions.  Since
  439.  
  440. executing a directory as a program is a meaningless operation,the
  441.  
  442. execute-permission bit, for directories, is taken instead to mean permission to
  443.  
  444. search the directory for a given file during the scanning of a path name; thus
  445.  
  446. if a directory has execute permission but no read permission for a given user,
  447.  
  448. he may access files with known names in the directory,but may not read (list)
  449.  
  450. the entire contents of the directory.
  451.  
  452.  
  453.  
  454. Write permission on a directory is interpreted to mean that the user may create
  455.  
  456. and delete files in that directory;it is impossible for any user to write
  457.  
  458. directly into any directory..Another, and from the point of view of security,
  459.  
  460. much more serious special case is that there is a ``super user'' who is able to
  461.  
  462. read any file and write any non-directory.The super-user is also able to change
  463.  
  464. the protection mode and the owner UID and GID of any file and to invoke
  465.  
  466. privileged system calls.It must be recognized that the mere notion of a
  467.  
  468. super-user is a theoretical, and usually practical, blemish on any protection
  469.  
  470. scheme.
  471.  
  472.  
  473.  
  474. The first necessity for a secure system is of course arranging that all files
  475.  
  476. and directories have the proper protection modes.Traditionally, UNIX software
  477.  
  478. has been exceedingly permissive in this regard;essentially all commands create
  479.  
  480. files readable and writable by everyone.In the current version,this policy may
  481.  
  482. be easily adjusted to suit the needs ofthe installation or the individual user.
  483.  
  484.  
  485.  
  486. Associated with each process and its descendants is a mask, which is in effect
  487.  
  488. anded with the mode of every file and directory created by that process.  In
  489.  
  490. this way, users can arrange that, by default,all their files are no more
  491.  
  492. accessible than they wish.The standard mask, set by login,allows all permiss-
  493.  
  494. ions to the user himself and to his group,but disallows writing by others.
  495.  
  496.  
  497.  
  498. To maintain both data privacy and data integrity,it is necessary, and largely
  499.  
  500. sufficient,to make one's files inaccessible to others.  The lack of sufficiency
  501.  
  502. could follow from the existence of set-UID programs created by the user and the
  503.  
  504. possibility of total breach of system security in one of the ways discussed
  505.  
  506. below(or one of the ways not discussed below).
  507.  
  508.  
  509.  
  510. For greater protection,an encryption scheme is available.Since the editor is
  511.  
  512. able to create encrypted documents, and the crypt command can be used to pipe
  513.  
  514. such documents into the other text-processing programs,the length of time
  515.  
  516. during which clear text versions need be available is strictly limited.The
  517.  
  518. encryption scheme used is not one of the strongest known, but it is judged
  519.  
  520. adequate, in the sense that cryptanalysisis likely to require considerably more
  521.  
  522. effort than more direct methods of reading the encrypted files.For example, a
  523.  
  524. user who stores data that he regards as truly secret should be aware that he is
  525.  
  526. implicitly trusting the system administrator not to install a version of the
  527.  
  528. crypt command that stores every typed password in a file.  Needless to say, the
  529.  
  530. system administrators must be at least as careful as their most demanding user
  531.  
  532. to place the correct protection mode on the files under their control.
  533.  
  534.  
  535.  
  536. In particular,it is necessary that special files be protected from writing, and
  537.  
  538. probably reading, by ordinary users when they store sensitive files belonging
  539.  
  540. to otherusers.It is easy to write programs that examine and change files by
  541.  
  542. accessing the device on which the files live.
  543.  
  544.  
  545.  
  546. On the issue of password security,UNIX is probably better than most systems.
  547.  
  548. Passwords are stored in an encrypted form which, in the absence of serious
  549.  
  550. attention from specialists in the field,appears reasonably secure, provided its
  551.  
  552. limitations are understood.In the current version, it is based on a slightl y
  553.  
  554. defective version of the Federal DES;it is purposely defective so that
  555.  
  556. easily-available hardware is useless for attempts at exhaustive
  557.  
  558. key-search.Since both the encryption algorithm and the encrypted passwords are
  559.  
  560. available,exhaustive enumeration of potential passwords is still feasible up to
  561.  
  562. a point.We have observed that users choose passwords that are easy to
  563.  
  564. guess:they are short, or from a limited alphabet, or in a dictionary.
  565.  
  566. Passwords should be at least six characters long and randomly chosen from an
  567.  
  568. alphabet which includes digits and special characters.
  569.  
  570.  
  571.  
  572. Of course there also exist feasible non-cryptanalytic ways of finding out
  573.  
  574. passwords.For example:    write a program which types out ``login:''on the
  575.  
  576. typewriter and copies whatever is typed to a file of your own.    Then invoke the
  577.  
  578. command and go away until the victim arrives..The set-UID (set-GID)notion must
  579.  
  580. be used carefully if any security is to be maintained.    The first thing to keep
  581.  
  582. in mind is that a writable set-UID file can have another program copied onto
  583.  
  584. it.
  585.  
  586.  
  587.  
  588. For example, if the super-user command is writable,anyone can copy the shell
  589.  
  590. onto it and get a password-free version of Shell Unix.A more subtle problem can
  591.  
  592. come from set-UID programs which are not sufficiently careful of what is fed
  593.  
  594. into them.To take an obsolete example,the previous version of the mail command
  595.  
  596. was set-UID and owned by the super-user.This version sent mail to the r
  597.  
  598. ecipient's own directory.The notion was that one should be able to send mail to
  599.  
  600. anyone even if they want to protecttheir directories from writing.  The trouble
  601.  
  602. was that mailwas rather dumb:anyone could mail someone else's priva te file to
  603.  
  604. himself.Much more seriousis the following scenario:  make a file with a line
  605.  
  606. like one in the password filewhich allows one to log in as the super-user.Then
  607.  
  608. make a link named ``.mail'' to the password file in some writable directory on
  609.  
  610. the same device as the password file (say /tmp).  Finally mail the bogus login
  611.  
  612. line to /tmp/.mail;You can then login as the superuser,clean up the
  613.  
  614. incriminating evidence,and have your will.
  615.  
  616.  
  617.  
  618. The fact that users can mount their own disks and tapes as file systems can be
  619.  
  620. another way of gaining super-user status.Once a disk pack is mounted, the
  621.  
  622. system believes what is on it.Thus one can take a blank disk pack,put on it
  623.  
  624. anything desired,and mount it.There are obvious and unfortunate consequences.
  625.  
  626. For example:a mounted disk with garbage on it will crash the system;one of the
  627.  
  628. files on the mounted disk can easily be a password-free version of Shell Unix;
  629.  
  630. other files can be unprotected entries for special files.  The only easy fix
  631.  
  632. for this problem is to forbid the use of mount to unpriv- ileged users.A
  633.  
  634. partial solution, not so restrictive,would be to have the mount command examine
  635.  
  636. the special file for bad data,set-UID programs owned by others ,and accessible
  637.  
  638. special files,and balk at unprivileged invokers.
  639.  
  640.  
  641.  
  642.  
  643.  
  644. Scott Walters   London, CANADA
  645. walterss@julian.uwo.ca  <CarbonBoy>
  646. PGP 31 03 1B E1 C7 6E 3A EC  97 32 01 BA 5B 05 5D FB
  647. finger me for public key block
  648. MIME-mail welcome
  649.  
  650. 'Beware the fury of a patient man.'
  651.  
  652.